home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / spriteCG4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-12  |  12.6 KB  |  482 lines

  1. /*-
  2.  * spriteCG4C.c --
  3.  *    Functions to support the sun CG4 board as a memory frame buffer.
  4.  */
  5.  
  6. /************************************************************
  7.  * Copyright (c) 1989 by the Regents of the University of California
  8.  *
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  ********************************************************/
  17.  
  18. #ifndef    lint
  19. static char rcsid[] =
  20.     "";
  21. #endif
  22.  
  23. #include    "spriteddx.h"
  24. #include    "os.h"
  25. #include    "resource.h"
  26.  
  27. #include    <sys.h>
  28. #include    <kernel/vmSunConst.h>
  29.  
  30. #include    "colormap.h"
  31. #include    "colormapst.h"
  32.  
  33. #define    CG4_HEIGHT    900
  34. #define    CG4_WIDTH    1152
  35.  
  36. /*
  37.  * Colormap stuff
  38.  */
  39. static ColormapPtr spriteCG4InstalledMap;
  40.  
  41. /* Brooktree DAC */
  42. typedef volatile struct {
  43.     unsigned int    addr;        /* colormap address register */
  44.     unsigned int    cmap;        /* colormap data register */
  45.     unsigned int    ctrl;        /* control register */
  46.     unsigned int    omap;        /* overlay map data register */
  47. } CG4Cmap;
  48.  
  49. /* copy of colormap */
  50. static union {
  51.     unsigned char    map[256][3];    /* reasonable way to access */
  52.     unsigned int    raw[256*3/4];    /* unreasonable way used to load h/w */
  53. } mCmap;
  54.     
  55. extern int TellLostMap(), TellGainedMap();
  56.  
  57. static void
  58. spriteCG4UpdateColormap(pScreen, index, count, rmap, gmap, bmap)
  59.     ScreenPtr        pScreen;
  60.     int            index, count;
  61.     unsigned char    *rmap, *gmap, *bmap;
  62. {
  63.     unsigned char    *uPtr;
  64.     unsigned int    *iPtr, c;
  65.     volatile CG4Cmap    *cMap = (CG4Cmap *)spriteFbs[pScreen->myNum].cmap;
  66.  
  67.     /* update the memory copy */
  68.     uPtr = &mCmap.map[index][0];
  69.     c = count;
  70.     rmap+=index; gmap+=index; bmap+=index;
  71.     while(c--) {
  72.     *uPtr++ = *rmap++;
  73.     *uPtr++ = *gmap++;
  74.     *uPtr++ = *bmap++;
  75.     }
  76.  
  77.     /* update DAC with the weird 4/3 entries per word mapping */
  78. #define D4M3(x)    ((((x)>>2)<<1) + ((x)>>2))    /* (x/4)*3 */
  79. #define    D4M4(x)    ((x)&~0x3)            /* (x/4)*4 */
  80.     iPtr = &mCmap.raw[D4M3(index)];
  81.     c = D4M3(index+count-1) - D4M3(index) + 3;
  82.     cMap->addr = D4M4(index);
  83.     while(c--) {
  84.     cMap->cmap = *iPtr++;
  85.     }
  86. }
  87.  
  88. static void
  89. spriteCG4InitColormap(pScreen)
  90.     ScreenPtr        pScreen;
  91. {
  92.     volatile CG4Cmap    *cMap = (CG4Cmap *)spriteFbs[pScreen->myNum].cmap;
  93.     cMap->addr = 6;    /* command register address */
  94.     cMap->ctrl = 0x70;    /* disable overlay */
  95. }
  96.  
  97. static void
  98. spriteCG4CloseColormap(pScreen)
  99.     ScreenPtr        pScreen;
  100. {
  101.     volatile CG4Cmap    *cMap = (CG4Cmap *)spriteFbs[pScreen->myNum].cmap;
  102.     cMap->addr = 6;    /* command register address */
  103.     cMap->ctrl = 0x73;    /* enable overlay */
  104. }
  105.  
  106. /*-
  107.  *-----------------------------------------------------------------------
  108.  * spriteCG4SaveScreen --
  109.  *    Preserve the color screen by turning on or off the video
  110.  *
  111.  * Results:
  112.  *    None.
  113.  *
  114.  * Side Effects:
  115.  *    Video state is switched
  116.  *
  117.  *-----------------------------------------------------------------------
  118.  */
  119. static Bool
  120. spriteCG4SaveScreen (pScreen, on)
  121.     ScreenPtr      pScreen;
  122.     Bool          on;
  123. {
  124. #ifdef    NONONONNEVER
  125.     if (on != SCREEN_SAVER_ON) {
  126.     SetTimeSinceLastInputEvent();
  127.     screenSaved = FALSE;
  128.     Sys_EnableDisplay(TRUE);
  129.     } else {
  130.     screenSaved = TRUE;
  131.     Sys_EnableDisplay (FALSE);
  132.     }
  133. #endif
  134.  
  135.     return TRUE;
  136. }
  137.  
  138. /*-
  139.  *-----------------------------------------------------------------------
  140.  * spriteCG4CloseScreen --
  141.  *    called to ensure video is enabled when server exits.
  142.  *
  143.  * Results:
  144.  *    Screen is unsaved.
  145.  *
  146.  * Side Effects:
  147.  *    None
  148.  *
  149.  *-----------------------------------------------------------------------
  150.  */
  151. /*ARGSUSED*/
  152. static Bool
  153. spriteCG4CloseScreen(i, pScreen)
  154.     int        i;
  155.     ScreenPtr    pScreen;
  156. {
  157.     spriteCG4CloseColormap(pScreen);
  158.     return ((* pScreen->SaveScreen)(pScreen, SCREEN_SAVER_OFF));
  159. #ifdef    FOOSUN
  160.     sunCG4InstalledMap = NULL;
  161.     return (pScreen->SaveScreen(pScreen, SCREEN_SAVER_OFF));
  162. #endif    FOOSUN
  163. }
  164.  
  165. /*-
  166.  *-----------------------------------------------------------------------
  167.  * spriteCG4InstallColormap --
  168.  *    Install given colormap.
  169.  *
  170.  * Results:
  171.  *    None
  172.  *
  173.  * Side Effects:
  174.  *    Existing map is uninstalled.
  175.  *    All clients requesting ColormapNotify are notified
  176.  *
  177.  *-----------------------------------------------------------------------
  178.  */
  179. static void
  180. spriteCG4InstallColormap(cmap)
  181.     ColormapPtr    cmap;
  182. {
  183.     register int    i;
  184.     register Entry    *pent = cmap->red;
  185.     unsigned char    rmap[256], gmap[256], bmap[256];
  186.  
  187.     if(cmap == spriteCG4InstalledMap)
  188.     return;
  189.     if(spriteCG4InstalledMap)
  190.     WalkTree(spriteCG4InstalledMap->pScreen, TellLostMap,
  191.          (char *) &(spriteCG4InstalledMap->mid));
  192.     for(i=0; i<cmap->pVisual->ColormapEntries; i++) {
  193.     if (pent->fShared) {
  194.         rmap[i] = pent->co.shco.red->color >> 8;
  195.         gmap[i] = pent->co.shco.green->color >> 8;
  196.         bmap[i] = pent->co.shco.blue->color >> 8;
  197.     }
  198.     else {
  199.         rmap[i] = pent->co.local.red >> 8;
  200.         gmap[i] = pent->co.local.green >> 8;
  201.         bmap[i] = pent->co.local.blue >> 8;
  202.     }
  203.     pent++;
  204.     }
  205.     spriteCG4InstalledMap = cmap;
  206.     spriteCG4UpdateColormap(cmap->pScreen, 0, 256, rmap, gmap, bmap);
  207.     WalkTree(cmap->pScreen, TellGainedMap, (char *) &(cmap->mid));
  208. }
  209.  
  210. /*-
  211.  *-----------------------------------------------------------------------
  212.  * spriteCG4UninstallColormap --
  213.  *    Uninstall given colormap.
  214.  *
  215.  * Results:
  216.  *    None
  217.  *
  218.  * Side Effects:
  219.  *    default map is installed
  220.  *    All clients requesting ColormapNotify are notified
  221.  *
  222.  *-----------------------------------------------------------------------
  223.  */
  224. static void
  225. spriteCG4UninstallColormap(cmap)
  226.     ColormapPtr    cmap;
  227. {
  228.     if(cmap == spriteCG4InstalledMap) {
  229.     Colormap defMapID = cmap->pScreen->defColormap;
  230.  
  231.     if (cmap->mid != defMapID) {
  232.         ColormapPtr defMap =
  233.         (ColormapPtr)LookupID(defMapID, RT_COLORMAP, RC_CORE);
  234.  
  235.         if (defMap)
  236.         spriteCG4InstallColormap(defMap);
  237.         else
  238.             ErrorF("spriteCG4: Can't find default colormap\n");
  239.     }
  240.     }
  241. }
  242.  
  243. /*-
  244.  *-----------------------------------------------------------------------
  245.  * spriteCG4ListInstalledColormaps --
  246.  *    Fills in the list with the IDs of the installed maps
  247.  *
  248.  * Results:
  249.  *    Returns the number of IDs in the list
  250.  *
  251.  * Side Effects:
  252.  *    None
  253.  *
  254.  *-----------------------------------------------------------------------
  255.  */
  256. /*ARGSUSED*/
  257. static int
  258. spriteCG4ListInstalledColormaps(pScreen, pCmapList)
  259.     ScreenPtr    pScreen;
  260.     Colormap    *pCmapList;
  261. {
  262.     *pCmapList = spriteCG4InstalledMap->mid;
  263.     return (1);
  264. }
  265.  
  266.  
  267. /*-
  268.  *-----------------------------------------------------------------------
  269.  * spriteCG4StoreColors --
  270.  *    Sets the pixels in pdefs into the specified map.
  271.  *
  272.  * Results:
  273.  *    None
  274.  *
  275.  * Side Effects:
  276.  *    None
  277.  *
  278.  *-----------------------------------------------------------------------
  279.  */
  280. static void
  281. spriteCG4StoreColors(pmap, ndef, pdefs)
  282.     ColormapPtr    pmap;
  283.     int        ndef;
  284.     xColorItem    *pdefs;
  285. {
  286.     switch(pmap->class) {
  287.     case PseudoColor:
  288.     if(pmap == spriteCG4InstalledMap) {
  289.         /* We only have a single colormap */
  290.         unsigned char    rmap[256], gmap[256], bmap[256];
  291.         int            index;
  292.  
  293.         while (ndef--) {
  294.         index = pdefs->pixel&0xff;
  295.         rmap[index] = (pdefs->red) >> 8;
  296.         gmap[index] = (pdefs->green) >> 8;
  297.         bmap[index] = (pdefs->blue) >> 8;
  298.          spriteCG4UpdateColormap(pmap->pScreen,
  299.                       index, 1, rmap, gmap, bmap);
  300.         pdefs++;
  301.         }
  302.     }
  303.     break;
  304.     case DirectColor:
  305.     default:
  306.     ErrorF("spriteCG4StoreColors: bad class %d\n", pmap->class);
  307.     break;
  308.     }
  309. }
  310.  
  311. /*-
  312.  *-----------------------------------------------------------------------
  313.  * spriteCG4ResolvePseudoColor --
  314.  *    Adjust specified RGB values to closest values hardware can do.
  315.  *
  316.  * Results:
  317.  *    Args are modified.
  318.  *
  319.  * Side Effects:
  320.  *    None
  321.  *
  322.  *-----------------------------------------------------------------------
  323.  */
  324. /*ARGSUSED*/
  325. static void
  326. spriteCG4ResolvePseudoColor(pRed, pGreen, pBlue, pVisual)
  327.     CARD16    *pRed, *pGreen, *pBlue;
  328.     VisualPtr    pVisual;
  329. {
  330.     *pRed &= 0xff00;
  331.     *pGreen &= 0xff00;
  332.     *pBlue &= 0xff00;
  333. }
  334.  
  335. /*-
  336.  *-----------------------------------------------------------------------
  337.  * spriteCG4Init --
  338.  *    Attempt to find and initialize a cg4 framebuffer
  339.  *
  340.  * Results:
  341.  *    TRUE if everything went ok. FALSE if not.
  342.  *
  343.  * Side Effects:
  344.  *    Most of the elements of the ScreenRec are filled in. Memory is
  345.  *    allocated for the frame buffer and the buffer is mapped. The
  346.  *    video is enabled for the frame buffer...
  347.  *
  348.  *-----------------------------------------------------------------------
  349.  */
  350. /*ARGSUSED*/
  351. static Bool
  352. spriteCG4Init (index, pScreen, argc, argv)
  353.     int              index;        /* The index of pScreen in the ScreenInfo */
  354.     ScreenPtr      pScreen;      /* The Screen to initialize */
  355.     int              argc;            /* The number of the Server's arguments. */
  356.     char          **argv;       /* The arguments themselves. Don't change! */
  357. {
  358.     CARD16    zero = 0, ones = ~0;
  359.  
  360.     if (!cfbScreenInit (index, pScreen, spriteFbs[index].fb,
  361.                 CG4_WIDTH, CG4_HEIGHT, 100))
  362.     return (FALSE);
  363.  
  364.     pScreen->SaveScreen    =            spriteCG4SaveScreen;
  365.     pScreen->RecolorCursor =             spriteRecolorCursor;
  366.  
  367. #ifndef STATIC_COLOR
  368.     pScreen->InstallColormap = spriteCG4InstallColormap;
  369.     pScreen->UninstallColormap = spriteCG4UninstallColormap;
  370.     pScreen->ListInstalledColormaps = spriteCG4ListInstalledColormaps;
  371.     pScreen->StoreColors = spriteCG4StoreColors;
  372.     pScreen->ResolveColor = spriteCG4ResolvePseudoColor;
  373. #endif
  374.  
  375.     spriteCG4InitColormap(pScreen);
  376.     {
  377.     ColormapPtr cmap = (ColormapPtr)LookupID(pScreen->defColormap,
  378.         RT_COLORMAP, RC_CORE);
  379.  
  380.     if (!cmap)
  381.         FatalError("Can't find default colormap\n");
  382.     if (AllocColor(cmap, &ones, &ones, &ones, &(pScreen->whitePixel), 0)
  383.         || AllocColor(cmap, &zero, &zero, &zero, &(pScreen->blackPixel), 0))
  384.         FatalError("Can't alloc black & white in spriteCG4Init\n");
  385.     spriteCG4InstallColormap(cmap);
  386.     }
  387.  
  388.     spriteCG4SaveScreen( pScreen, SCREEN_SAVER_OFF );
  389.     spriteScreenInit (pScreen);
  390.  
  391.     return (TRUE);
  392. }
  393.  
  394. /*-
  395.  *--------------------------------------------------------------
  396.  * spriteCG4Switch --
  397.  *      Enable or disable color plane 
  398.  *
  399.  * Results:
  400.  *      Color plane enabled for select =0, disabled otherwise.
  401.  *
  402.  *--------------------------------------------------------------
  403.  */
  404. static void
  405. spriteCG4Switch ()
  406. {
  407. }
  408.  
  409. /*-
  410.  *-----------------------------------------------------------------------
  411.  * spriteCG4Probe --
  412.  *    Attempt to find and initialize a cg4 framebuffer
  413.  *
  414.  * Results:
  415.  *    TRUE if everything went ok. FALSE if not.
  416.  *
  417.  * Side Effects:
  418.  *    Memory is allocated for the frame buffer and the buffer is mapped.
  419.  *    Same for colormap.
  420.  *
  421.  *-----------------------------------------------------------------------
  422.  */
  423. Bool
  424. spriteCG4Probe(screenInfo, index, fbNum, argc, argv)
  425.     ScreenInfo      *screenInfo;    /* The screenInfo struct */
  426.     int              index;        /* The index of pScreen in the ScreenInfo */
  427.     int              fbNum;        /* Index into the spriteFbData array */
  428.     int              argc;            /* The number of the Server's arguments. */
  429.     char          **argv;       /* The arguments themselves. Don't change! */
  430. {
  431.     Sys_MachineInfo    machType;
  432.     pointer          pFb, pCm;    /* preallocated VM */
  433.     Address          vFb, vCm;    /* kernel virtual addresses to poke */
  434.     unsigned int    bCm, oCm;    /* base&offset for segment for cmap */
  435.     unsigned int    sFb, sCm;    /* how much mem to alloc */
  436.  
  437.     if(strlen(argv[0]) < 4 || strcmp("Xcg4", argv[0]+strlen(argv[0])-4) != 0)
  438.     return FALSE;
  439.  
  440.     if(!spriteFbs[index].mapped) {
  441.     if(Sys_GetMachineInfo(sizeof(machType), &machType) != SUCCESS) {
  442.         return FALSE;
  443.     }
  444.     if(machType.architecture == SYS_SUN4) {
  445.         if(machType.type == SYS_SUN_4_C) {
  446.         vFb = (Address)0xffd80000;    /* sparc station */
  447.         vCm = (Address)0xffd1c000;
  448.         } else {
  449.         vFb = (Address)0xffd40000;    /* regular sun4 */
  450.         vCm = (Address)0xffd1c000;    /* ??? */
  451.         }
  452.     } else if(machType.architecture == SYS_SUN3) {
  453.         vFb = (Address)0x0fd00000;    /* sun3 with Brooktree DAC */
  454.         vCm = (Address)0x0fe0e000;
  455.     } else {
  456.         return FALSE;
  457.     }
  458.  
  459.     sFb = (CG4_HEIGHT*CG4_WIDTH + VMMACH_SEG_SIZE - 1) / VMMACH_SEG_SIZE;
  460.     sFb *= VMMACH_SEG_SIZE;
  461.     sCm = VMMACH_SEG_SIZE;
  462.     pFb = (pointer)malloc(sFb + VMMACH_SEG_SIZE);
  463.     pCm = (pointer)malloc(sCm + VMMACH_SEG_SIZE);
  464.     oCm = (unsigned int)vCm -
  465.         ((unsigned int)vCm)/VMMACH_SEG_SIZE*VMMACH_SEG_SIZE;
  466.     vCm = (Address)(((unsigned int)vCm)/VMMACH_SEG_SIZE*VMMACH_SEG_SIZE);
  467.  
  468.     if(Vm_MapKernelIntoUser(vFb, sFb, pFb, &spriteFbs[index].fb) != SUCCESS)
  469.           { perror("VmMap"); return (FALSE); }
  470.     if(Vm_MapKernelIntoUser(vCm, sCm, pCm, &bCm) != SUCCESS)
  471.           return (FALSE);
  472.     spriteFbs[index].cmap = (pointer)(bCm+oCm);
  473.     spriteFbs[index].mapped = TRUE;
  474.     }
  475.     if(AddScreen(spriteCG4Init, argc, argv) > index) {
  476.     screenInfo->screen[index].CloseScreen = spriteCG4CloseScreen;
  477.     return TRUE;
  478.     } else {
  479.     return FALSE;
  480.     }
  481. }
  482.